package me.cxlr.shaopinghelper.widget;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.CompoundButton;

import androidx.annotation.NonNull;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.appcompat.widget.LinearLayoutCompat;
import androidx.appcompat.widget.SwitchCompat;
import androidx.cardview.widget.CardView;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.content.res.ResourcesCompat;

import me.cxlr.shaopinghelper.R;

/**
 * 控件--卡片式Switch组件
 *
 * @author ShanLunZhi
 */
public class CardViewSwitchWidget extends LinearLayoutCompat {
    private Context context;
    private View view;
    private CardView cardView;
    private ConstraintLayout llcRoot;
    private AppCompatTextView textViewTitle;
    private AppCompatTextView textViewMessage;
    private SwitchCompat switchCompat;

    public CardViewSwitchWidget(@NonNull Context context) {
        super(context);
        this.context = context;
        initWidget();
    }

    public CardViewSwitchWidget(Context context, AttributeSet attributeSet) {
        super(context, attributeSet);
        this.context = context;
        initWidget();
    }

    private void initWidget() {
        view = LayoutInflater.from(context).inflate(R.layout.widget_cardview_switch, this);
        cardView = view.findViewById(R.id.wcswitch_cv);
        llcRoot = view.findViewById(R.id.wcswitch_ll_root);
        textViewTitle = view.findViewById(R.id.wcswitch_tv_title);
        textViewMessage = view.findViewById(R.id.wcswitch_tv_message);
        switchCompat = view.findViewById(R.id.wcswitch_switch);

        cardView.setRadius(35F);
    }

    public void setTitle(int resourceId) {
        textViewTitle.setText(resourceId);
    }

    public void setTitle(CharSequence title) {
        textViewTitle.setText(title);
    }

    public void setMessage(int resourceId) {
        textViewMessage.setText(resourceId);
    }

    public void setMessage(CharSequence title) {
        textViewMessage.setText(title);
    }

    public void setChecked(boolean bool) {
        switchCompat.setChecked(bool);
    }

    public void setOnCheckedChangeListener(CompoundButton.OnCheckedChangeListener listener) {
        switchCompat.setOnCheckedChangeListener(listener);
    }
}
